﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace KingOfCSharp.iHunter.Plugins.BBS
{
    public enum HostType
    {
        Net9,
        SMTH
    }

    abstract class HostConfigure
    {
        public List<ExceptionalQuestion> Questions
        {
            get;
            protected set;
        }

        public string MainMenuToBoard
        {
            get;
            protected set;
        }

        public string BoardToMainMenu
        {
            get;
            protected set;
        }

        public string MainMenuToMailbox
        {
            get;
            protected set;
        }

		public string MainMenuToSentMailbox
		{
			get;
			protected set;
		}

        public string MailboxToMainMenu
        {
            get;
            protected set;
        }

        public string PreSendMailCommand
        {
            get;
            protected set;
        }

        public string PostSendMailCommand
        {
            get;
            protected set;
        }

        public Regex MailboxEntry
        {
            get;
            protected set;
        }
    }

    public class ExceptionalQuestion
    {
        public Regex Question
        {
            get;
            private set;
        }

        public string Operation
        {
            get;
            private set;
        }

        public ExceptionalQuestion(string q, string op)
        {
            this.Question = new Regex(q);
            this.Operation = op;
        }
    }

    static class HostConfigureFactory
    {
        public static HostConfigure GetHostConfigure(HostType type)
        {
            if (type == HostType.Net9)
                return new Net9HostConfigure();
            else
                return new SmthHostConfigure();
        }
    }

    internal class Net9HostConfigure : HostConfigure
    {
        public Net9HostConfigure()
        {
            this.MainMenuToMailbox = "m\rr\r";
			this.MainMenuToSentMailbox = "m\rp\r";
            this.BoardToMainMenu = "qq";
            this.MailboxToMainMenu = "qe";
            this.MainMenuToBoard = "b\rs";            
            this.PreSendMailCommand = "m\rs\r";
            this.PostSendMailCommand = "e";
            this.MailboxEntry = new Regex(@"\(M\)ail\s*处理信笺");

            this.Questions = new List<ExceptionalQuestion>();
            this.Questions.Add(new ExceptionalQuestion("你同时上线的窗口数过多，是否踢出本ID其它窗口", "y\r"));
            this.Questions.Add(new ExceptionalQuestion("您要删除以上密码输入错误的记录吗", "y\r"));
            this.Questions.Add(new ExceptionalQuestion("下面还有喔.*开头末尾","q"));
            this.Questions.Add(new ExceptionalQuestion("按.*RETURN.*继续", "\r"));
            this.Questions.Add(new ExceptionalQuestion("上次连线时间为","\r"));
            this.Questions.Add(new ExceptionalQuestion("按任何键继续","\r"));
            this.Questions.Add(new ExceptionalQuestion("按任意键继续","\r"));

        }
    }

    internal class SmthHostConfigure : HostConfigure
    {
        public SmthHostConfigure()
        {
            this.MainMenuToMailbox = "m\rr\r";
			this.MainMenuToSentMailbox = "m\rp\r";
            this.BoardToMainMenu = "qq";
            this.MailboxToMainMenu = "qe";
            this.MainMenuToBoard = "x\rs";
            this.PreSendMailCommand = "m\rs\r";
            this.PostSendMailCommand = "e";
            this.MailboxEntry = new Regex(@"M\)\s+信件处理");

            this.Questions = new List<ExceptionalQuestion>();
            this.Questions.Add(new ExceptionalQuestion("请输入编号，回车忽略:", "1\r"));
            this.Questions.Add(new ExceptionalQuestion("如何处理以上密码输入错误记录", "y\r"));
            this.Questions.Add(new ExceptionalQuestion("下面还有喔.*开头末尾", "q"));
            this.Questions.Add(new ExceptionalQuestion("按.*RETURN.*继续", "\r"));
            this.Questions.Add(new ExceptionalQuestion("上次连线时间为", "\r"));
            this.Questions.Add(new ExceptionalQuestion("按任何键继续", "\r"));
            this.Questions.Add(new ExceptionalQuestion("按任意键继续", "\r"));

        }
    }
}
